// banShare 为true 禁止页面分享
// targetPath 自定义分享页面路径

module.exports = {
	onLoad(options) {
		console.log(options,111)
		//二维码进入
	    if(options.scene){
			var scene=options.scene
			uni.setStorageSync("uid",options.scene)    	
		}
		//链接进入
		if (options.uid) {
			
			uni.setStorageSync("uid",options.uid)    		
		}
		if(this.$data.banShare) uni.hideShareMenu()
		// 设置默认的转发参数
		
		this.$u.mpShare = {
			title: '车小吉', // 默认为小程序名称
			path: '', // 默认为当前页面路径
			imageUrl: '' // 默认为当前页面的截图
		}
	},
	methods: {
		currentPage() {
			//分享页面携带用户id和页面参数
			var pagesArr = getCurrentPages();
			if (this.$data.targetPath) var currentPagePath = this.$data.targetPath //自定义分享页面路径
			else var currentPagePath = pagesArr[pagesArr.length - 1].route; //系统分享页面路径
			var currentPageOption = this.$u.queryParams(pagesArr[pagesArr.length - 1].options); //获取当前页面参数页面
			var uid = uni.getStorageSync('userInfo').mid || ''
			if (currentPageOption.indexOf('?') !== -1) {
				this.$u.mpShare.path = '/' + currentPagePath + currentPageOption + '&uid=' + uid
			} else {
				this.$u.mpShare.path = '/' + currentPagePath + currentPageOption + '?uid=' + uid
			}
			if(this.$data.isTitle){
				this.$u.mpShare.title = this.$data.isTitle
			}
			if(this.$data.isImageUrl){
				this.$u.mpShare.imageUrl = this.$data.isImageUrl
			}
		}
	},
	onShareAppMessage() {
		this.currentPage()
		console.log(this.$u.mpShare)
		return this.$u.mpShare
	},
	// #ifdef MP-WEIXIN
	onShareTimeline() {
		this.currentPage()
		return this.$u.mpShare
	}
	// #endif
}
